﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for PageBase
/// </summary>
public class PageBase : System.Web.UI.Page
{
    protected int IdPatrocinador
    {
        get { return int.Parse(((Session["IdPatrocinador"] == null) ? "0" : Session["IdPatrocinador"].ToString())); }
        set { Session["IdPatrocinador"] = value; }
    }
    protected int IdPrestador
    {
        get { return int.Parse(((Session["IdPrestador"] == null) ? "0" : Session["IdPrestador"].ToString())); }
        set { Session["IdPrestador"] = value; }
    }
    protected int IdContrato
    {
        get { return int.Parse(((Session["IdContrato"] == null) ? "0" : Session["IdContrato"].ToString())); }
        set { Session["IdContrato"] = value; }
    }
    protected int IdPessoa
    {
        get { return int.Parse(((Session["IdPessoa"] == null) ? "0" : Session["IdPessoa"].ToString())); }
        set { Session["IdPessoa"] = value; }
    }

    protected string formatarValor(TypeCode tipo, string valor)
    {
        string ret = valor;
        switch (tipo)
        {
            case TypeCode.DateTime:
                ret = formatarDataHora(valor);
                break;

            case TypeCode.Int32:
                ret = formatarNumero(valor);
                break;
        }

        return ret;
    }
    protected string formatarDataHora(string dataHora)
    {
        DateTime dtTmp = DateTime.Parse(dataHora);
        return dtTmp.ToString("yyyy-MM-dd HH:mm:ss");
    }

    protected string formatarNumero(string valorNumerico)
    {
        return int.Parse(valorNumerico).ToString();
    }

    protected void CopiarArquivo(string name, string sourcePath, string newName, string targetPath)
    {
        //string fileName = "test.txt";
        //string sourcePath = @"C:\Users\Public\TestFolder";
        //string targetPath = @"C:\Users\Public\TestFolder\SubDir";

        // Use Path class to manipulate file and directory paths.
        string sourceFile = System.IO.Path.Combine(sourcePath, name);
        string destFile = System.IO.Path.Combine(targetPath, newName);

        // To copy a folder's contents to a new location:
        // Create a new target folder, if necessary.
        if (!System.IO.Directory.Exists(targetPath))
        {
            System.IO.Directory.CreateDirectory(targetPath);
        }

        // To copy a file to another location and 
        // overwrite the destination file if it already exists.
        System.IO.File.Copy(sourceFile, destFile, true);
    }
}
